"ui";
var qq_number = '你的qq';
getImei();

var ColoredButton = (function () {
    //继承ui.Widget
    util.extend(ColoredButton, ui.Widget);

    function ColoredButton() {
        //调用父类构造函数
        ui.Widget.call(this);
        //自定义属性color，定义按钮颜色
        this.defineAttr("color", (view, name, defaultGetter) => {
            return this._color;
        }, (view, name, value, defaultSetter) => {
            this._color = value;
            view.attr("backgroundTint", value);
        });
        //自定义属性onClick，定义被点击时执行的代码
        this.defineAttr("onClick", (view, name, defaultGetter) => {
            return this._onClick;
        }, (view, name, value, defaultSetter) => {
            this._onClick = value;
        });
    }
    ColoredButton.prototype.render = function () {
        return (
            <button textSize="16sp" style="Widget.AppCompat.Button.Colored" w="auto" />
        );
    }
    ColoredButton.prototype.onViewCreated = function (view) {
        view.on("click", () => {
            if (this._onClick) {
                eval(this._onClick);
            }
        });
    }
    ui.registerWidget("colored-button", ColoredButton);
    return ColoredButton;
})();




ui.layout(
    <vertical>
        <appbar>
            <toolbar title="激活页" textStyle="bold" />
        </appbar>
        {/* <card w="*" h="50" margin="10 5" cardCornerRadius="2dp"
            cardElevation="1dp" gravity="center_vertical">
            <vertical padding="18 8" h="auto">
                <text id="tishi" text="请激活后查看到期状态......" textStyle="bold" gravity="center" textColor="red" textSize="18" />
            </vertical>
            <View bg="#ea0000" h="*" w="10" />
        </card> */}
        <card w="*" h="80" margin="10 5" cardCornerRadius="2dp"
            cardElevation="1dp" gravity="center_vertical">
            <vertical padding="18 8" h="auto">
                <text id='imei' text="激活过程中请保持后台" textStyle="bold" textColor="#009868" textSize="16" />
                <text text="请先复制设备号/联系管理获取卡密" textColor="#999999" textSize="14" />
            </vertical>
            <View bg="#2196f3" h="*" w="10" />
        </card>

        <button id="imeiNumber" text="复制设备号" textStyle="bold" style="Widget.AppCompat.Button.Colored" w="*" h="50" margin="10 5" />
        <colored-button id="start" text="联系作者" color="#ff6347" textStyle="bold" style="Widget.AppCompat.Button.Colored" w="*" h="50" margin="10 5" />
    </vertical>
);

ui.start.on('click', function () {
    app.startActivity({
        action: "android.intent.action.VIEW",
        data: "mqq://im/chat?chat_type=wpa&version=1&src_type=web&uin="+qq_number,
        packageName: "com.tencent.mobileqq",
    });
})

function getImei(){
    events.on("imei", function (imei) {
        ui.run(()=>{
            ui.imei.setText(imei)
        })
        ui.imeiNumber.on("click", function () {
            setClip(imei); 
            toastLog("已复制到剪贴板")
        })
    });
    
    //保持脚本运行
    setInterval(() => { }, 5*60000);
}
